package com.xiaoran.service;

import com.xiaoran.service.connector.RpcServerAcceptor;
import com.xiaoran.service.zk.ServicePushManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class RpcServerRunner {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(RpcServerRunner.class);
    private static ExecutorService executor = null;
    @Autowired
    private ServicePushManager servicePushManager;
    
    
    public void run() {
        executor= Executors.newFixedThreadPool(5);
        executor.execute(new RpcServerAcceptor());
        servicePushManager.registerIntoZK();
    }

    @PreDestroy
    public void destroy(){
        if (executor!=null){
            executor.shutdown();
        }
    }
}
